<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="p" uri="/WEB-INF/tld/paging.tld"%>
<c:set var="path" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<title>首页</title>
<meta name="content-type" content="text/html; charset=utf-8">
<!-- <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
    <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> -->
<link rel="stylesheet" href="${path }/static/bootstrap.min.css" />
<script src="${path }/static/jquery.min.js"></script>
<script src="${path }/static/js/bootstrap.min.js"></script>
<script type="text/javascript">
	function login() {
		window.location.href = "login";
	}

	function register() {
		window.location.href = "register";
	}

	function uplaod() {
		window.location.href = "post";
	}

	// 分页代码
	/* $(document).ready(function(){ 
	    $("tbody tr:gt(20)").hide();//初始化，前面4条数据显示，其他的数据隐藏。 
	    //var total_q=$("#l").index()+1;//总数据 
	    var total_q=$("tbody").children().length;//总数据 
	    //alert(total_q);  
	    var current_page=20;//每页显示的数据 
	    var current_num=1;//当前页数
	    var total_page= Math.ceil(total_q/current_page);//总页数
	    var next=$(".next");//下一页 
	    var prev=$(".prev");//上一页 
	    $(".total").text(total_page);//显示总页数 
	    $(".current_page").text(current_num);//当前的页数 
	      
	    //下一页 
	    $(".next").click(function(){ 
	        if(current_num== total_page){ 
	                return false;//如果大于总页数就禁用下一页 
	            } 
	            else{ 
	                $(".current_page").text(++current_num);//点击下一页的时候当前页数的值就加1 
	                $.each($('tbody tr'),function(index,item){ 
	                    var start = current_page* (current_num-1);//起始范围 
	                    var end = current_page * current_num;//结束范围 
	                    if(index >= start && index < end){//如果索引值是在start和end之间的元素就显示，否则就隐 
	                        $(this).show(); 
	                    }else { 
	                        $(this).hide();  
	                    } 
	                }); 
	            } 
	    }); 
	    
	    //上一页方法 
	    $(".prev").click(function(){ 
	            if(current_num==1){ 
	                return false; 
	            }else{ 
	                $(".current_page").text(--current_num); 
	                $.each($('tbody tr'),function(index,item){ 
	                    var start = current_page* (current_num-1);//起始范围 
	                    var end = current_page * current_num;//结束范围 
	                    if(index >= start && index < end){//如果索引值是在start和end之间的元素就显示，否则就隐藏 
	                        $(this).show(); 
	                    }else { 
	                        $(this).hide();  
	                    } 
	                });      
	            } 
	        }) 
		}) 	    */
</script>
<style type="text/css">
.page_btn {
	margin-bottom: 50px;
	margin-left: 540px;
}

.page_btn a {
	cursor: pointer;
	padding: 5px;
	font-size: 15px;
	margin: 0 5px;
	
}

/* .page_box {
	/* float: right; 
}*/

.num {
	padding: 0 10px;
}
</style>
</head>

<body>
	<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
		<div class="container">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed"
					data-toggle="collapse" data-target="#navbar" aria-expanded="false"
					aria-controls="navbar">
					<span class="sr-only">Toggle navigation</span> <span
						class="icon-bar"></span> <span class="icon-bar"></span> <span
						class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="<c:url value="/index"></c:url>">论坛系统的实现
				</a>
			</div>
			<form class="navbar-form navbar-left" role="search" action="${path }/search" method="post">
				<div class="form-group">
					<input type="text" class="form-control" placeholder="搜索帖子" name="test">
				</div>
				<button type="submit" class="btn btn-default">搜索</button>
			</form>
			<div class="navbar-right" style="margin-right: 50px">
				<c:if test="${not empty user}">
					<h4>
						<div class="btn-group">
 <a href="<c:url value="/personal/person"/>"> ${user.nickname} 
					<c:if test="${user.status==0 }">(未激活)</c:if>
				</a>
  <a  style="margin-right: 20px" data-toggle="dropdown" aria-expanded="false">
    <span class="caret"></span>
    <span class="sr-only">Toggle Dropdown</span>
  </a>
  <ul class="dropdown-menu" role="menu">
    <li><a href="${path }/personal/resetpassword">修改密码</a></li>
    <li><a href="${path }/personal/upload">上传头像</a></li>
    <li><a href="${path }/personal/mypost">贴子管理</a></li>
    <!-- <li class="divider"></li> -->
   <!--  <li><a href="#">Separated link</a></li> -->
  </ul>
</div>
						</a> <a href="<c:url value="/user/logout"></c:url>"
							class="btn btn-sm btn-warning">退出</a>
					</h4>
					<!-- <button class="btn  btn-primary " type="button" id="login_btn" style="margin-left: 20px;margin-bottom: 10px" onclick="center();">个人中心</button> -->
				</c:if>
				<c:if test="${ empty user}">
					<a href="<c:url value='/login'/>" class="btn  btn-primary"
						style="margin-left: 20px; margin-top: 10px;">登录</a>
					<a href="<c:url value='/register'/>" class="btn  btn-primary"
						style="margin-left: 20px; margin-top: 10px;">注册</a>
				</c:if>
			</div>
		</div>
	</nav>

	<div class="panel panel-info"
		style="width: 1000px; margin-left: 200px; margin-top: 52px;">
		<div class="panel-heading" style="height: 50px">
			<h2 class="panel-title pull-left" style="margin-top: 10px">所有帖子</h2>
			<div class="pull-right">
				<button class="btn  btn-primary " type="button" onclick="uplaod();">发帖</button>
			</div>
		</div>

		<div class="panel-body">
			<table class="table table-striped">
				<thead>
					<tr>
						<th width="400px">标题</th>
						<th>发贴人</th>
						<th>发布时间</th>
						<th>阅读数</th>
						<th>回复数</th>
					</tr>
				</thead>
				<tbody>
					<c:if test="${not empty requestScope.postArrayList }">
						<c:forEach items="${postArrayList}" var="post" varStatus="status">
							<tr>
								<td><a
									href="<c:url value="/reply/replies/${post.postid}"/>">${post.postTitle}</a></td>
								<td>${post.postUsername}</td>
								<td><fmt:formatDate value="${post.postCreatetime}"
										pattern="yyyy-MM-dd  HH:mm" /></td>
								<c:if test="${post.postRead ==null}">
									<th>0</th>
								</c:if>
								<c:if test="${post.postRead !=null}">
									<th>${post.postRead}</th>
								</c:if>
								<th>${post.postResponse}</th>
							</tr>
						</c:forEach>
					</c:if>
				</tbody>
			</table>
		</div>
	</div>
	 <div class="page_btn clear">
		<p:paging currPage="${page.pageIndex}" url="${path }/post/all"
			totalRecords="${page.totalField }" isAppoint="false" />
	</div> 
</body>
</html>